#ifndef SPINACH_H
#define SPINACH_H

#include "Sprite.h"
#include "Popeye.h"
#include "SpinachBox.h"
#include "CollisionChecker.h"
#include <list>

class Spinach : public Sprite {
	std::list<SpinachBox *> spinachBoxList;
	bool taken;
public:
	Spinach(Dim _x, Dim _y, AnimationFilm *film): taken(false),
	  spinachBoxList(NULL), Sprite(_x, _y, film) {}; 
	virtual void ResetToDefaultFilm() {};
	void Hide(void) { 
		this->SetVisibility(false);
		//Collision should be now canceled, and AI should register it again,
		//after PlaceOnNextSpinachBox(...)
	};

	void PlaceOnNextSpinachBox(void) {
		this->SetVisibility(!this->taken);
		SpinachBox *sbox = (SpinachBox *)spinachBoxList.front();
		spinachBoxList.pop_front();
		spinachBoxList.push_back(sbox); //list recycles boxes
		sbox->AlignOnTop(this);
	};

	void AddSpinachBox(SpinachBox *sbox) {
		spinachBoxList.push_back(sbox);
	};

	static void GenerateNextMove(void *closure) {
		Spinach *player = (Spinach *)closure;
		player->PlaceOnNextSpinachBox();
	};

	virtual void CollisionAction(Sprite *s) {
		//spinach should collide only with popeye
		Popeye *p = (Popeye*)s;
		if(!taken && p->Punches()) {
			if(p->getMode() == normal) {
				((Popeye*)s)->changeMode();
			}
			taken = true;
			Hide();
		}
	};
};

#endif